<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/bootstrap.css">
    <script src="./js/jquery.min.js"></script>
    <script src="./js/popper.min.js"></script>
    <script src="./js/bootstrap.min.js"></script>
    <script>
        console.assert(location.href)
        //方法一
        var _uid= location.href.split('?')[1];
        var id=_uid.split('=')[1];
        //方法二
        // var obj=new URLSearchParams(location.search)
        // var uid=obj.get('uid')
          function getUser(){

              var xhr=new XMLHttpRequest()
              xhr.onreadystatechange=function(){
                  if(xhr.readyState==4&&xhr.status==200){
                      console.log(xhr.responseText);
                      var user=JSON.parse(xhr.responseText)[0]
                      console.log(user)
                      uid.value=user.uid
                      uname.value=user.uname
                      upwd.value=user.upwd
                  }
              }
              xhr.open('get',`/search?uid=${id}`,true)
              xhr.send()
          }
          function update(){
              var uid2=uid.value
              var uname2=uname.value
              var upwd2=upwd.value
            var xhr=new XMLHttpRequest()
            xhr.onreadystatechange=function(){
                if(xhr.readyState==4&&xhr.status==200){
                    var r=xhr.responseText
                    if(r==1){
                        alert('修改成功')
                        location.href='list.html'
                    }else{
                        alert('修改失败')
                    }
                }
            }
            xhr.open('get',`/update?uid=${uid2}&uname=${uname2}&upwd=${upwd2}`,true)
            xhr.send()
          }
    </script>
</head>
<body onload="getUser()">
    <h1>更新页面</h1>
    <form action="/update" method="get">
    id号 <input type="text" name="uid" id="uid" readonly> <br>
    账号 <input type="text" name="uname" id="uname"> <br>
    密码 <input type="text" name="upwd" id="upwd"> <br>
    <input type="submit" value="提交" >
    <button onclick="update()">提交更新</button>
</form>
</body>
</html>